#include<pthread.h>
#include<vector>
#include<string>
#include<cstdio>
#include<iostream>
#include <unistd.h>
using namespace std;

int *p=nullptr;
struct ThreadData
{
    string threadname;
};
string TOhex(pthread_t id)
{
    char buffer[128];
   snprintf(buffer, sizeof(buffer), "0x%x", id);
    return buffer;
}
void*threadrun(void *args)
{

    int test_i=0;
    ThreadData *td = static_cast<ThreadData *>(args);
    string id=TOhex(pthread_self());
    if(td->threadname=="threadname id--2")p=&test_i;

    int  pid=getpid();
 int i = 0;
    while (i < 10)
    {
        cout << "pid: " << getpid() << ", tid : "
            << TOhex(pthread_self()) << ", threadname: " << td->threadname<<",test_i:"<<test_i<<", &test_i:"<<&test_i
            <<endl;
        usleep(1000);
        ++test_i;
        i++;
    }

    delete td;
    return nullptr;

    //cout<<"Threadpid:"<<pid<<"TID"<<id<<endl;
}

void InitThreadData(ThreadData*id ,int number)
{
    id->threadname="threadname id-- "+to_string(number);
}
int main()
{
    //创建多线程
    vector<pthread_t>tids;
    for(int i=0;i<10;i++)
    {
        pthread_t tid;
        ThreadData*id=new ThreadData;
        InitThreadData(id,i);
        pthread_create(&tid,nullptr,threadrun,id);
        tids.push_back(tid);
        
    }
      sleep(1);
}